﻿@model CategoryModel
@inject AdminAreaSettings adminAreaSettings
@if (!string.IsNullOrEmpty(Model.Id))
{
    <div class="panel panel-default">
        <vc:admin-widget widget-zone="category_details_documents_top" additional-data="Model"/>
        <div class="panel-body">
            <div id="category-documents-grid"></div>
        </div>
        <div class="panel-footer">
            <button type="button" class="k-button" onclick="location.href='@Url.Action("CreateDocument", "Document", new { ObjectId = Model.Id, Reference = (int)Reference.Category, area = Constants.AreaAdmin })'"><i class="fa fa-plus"></i>&nbsp;@Loc["Admin.Marketing.Document.Add"]</button>
        </div>
        <vc:admin-widget widget-zone="category_details_documents_bottom" additional-data="Model"/>
    </div>

    <script>
        $(document).ready(function () {
            $("#category-documents-grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "@Html.Raw(Url.Action("ListDocuments", "Document", new { reference = (int)Reference.Category, ObjectId = Model.Id, StatusId = -1, area = Constants.AreaAdmin }))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        },
                    },
                    schema: {
                        data: "Data",
                        total: "Total",
                        errors: "Errors",
                    },
                    error: function(e) {
                        display_kendoui_grid_error(e);
                        // Cancel the changes
                        this.cancelChanges();
                    },
                    pageSize: @(adminAreaSettings.DefaultGridPageSize),
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                },
                autoBind: false,
                pageable: {
                    refresh: true,
                    pageSizes: [@(adminAreaSettings.GridPageSizes)]
                },
                editable: {
                    confirmation: true,
                    mode: "inline"
                },
                scrollable: false,
                columns: [{
                        field: "Number",
                        title: "@Loc["Admin.Documents.Document.Fields.Number"]",
                        template: '<a class="k-link" href="@Url.Action("EditDocument", "Document", new { area = Constants.AreaAdmin })/#=Id#">#=kendo.htmlEncode(Number)#</a>',
                    },
                    {
                        field: "Name",
                        title: "@Loc["Admin.Documents.Document.Fields.Name"]",
                        template: '<a class="k-link" href="@Url.Action("EditDocument", "Document", new { area = Constants.AreaAdmin })/#=Id#">#=kendo.htmlEncode(Name)#</a>',
                    }, {
                        field: "Published",
                        title: "@Loc["Admin.Documents.Document.Fields.Published"]",
                        width: 100,
                        minScreenWidth: 500,
                        headerAttributes: { style: "text-align:center" },
                        attributes: { style: "text-align:center" },
                        template: '# if(Published) {# <i class="fa fa-check" aria-hidden="true" style="color:green"></i> #} else {# <i class="fa fa-times" aria-hidden="true" style="color:red"></i> #} #'
                }]
            });
        });
    </script>
}
else
{
    <div class="note note-info">
        @Loc["Admin.Catalog.SaveBeforeEdit"]
    </div>
}